import { Message } from 'iview';

let counter = 0
let loadingMsg = null

const loading = {
  showLoading: function () {
    if (counter == 0) {
      loadingMsg = Message.loading({
        content: 'Loading...',
        duration: 0
      });
    }
    counter ++
  },
  hideLoading: function () {
    counter --
    if (counter <= 0) {
      counter = 0
      loadingMsg()
      loadingMsg = null
    }
  }
}

export default loading;